package com.zhengke.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.zhengke.dao.BaleGoodsDao;
import com.zhengke.pojo.BaleGoods;
import com.zhengke.pojo.Result;
import com.zhengke.pojo.TansferReturn;
import com.zhengke.service.BaleGoodsService;

/**  

* 创建时间：2019年12月26日 下午3:05:25  

* 项目名称：tvmall  

* @author 刘浩  

* @version 1.0     

* 文件名称：BaleGoodsServiceImpl.java   

* 类说明：  

*/
@Service
public class BaleGoodsServiceImpl implements BaleGoodsService{
	
	Result rs = new Result();
	@Autowired
	BaleGoodsDao bgd;
	
	@Override
	public Result selectBaleGoods(BaleGoods sth) {
		PageHelper.startPage(sth.getPage(), sth.getLimit(),true);
		List<BaleGoods> selectBaleGoodsList = bgd.selectBaleGoods(sth);
		int i=0;
		i = bgd.selectBaleGoodsCount(sth);
		rs.setCount(i);
		rs.setData(selectBaleGoodsList);
		rs.setCode(0);
		rs.setMsg("success");
		return rs;
	}

	@Override
	public String addBaleGoods(BaleGoods sth) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		String format = df.format(new Date());
		sth.setCreateDate(format);
		String picpath = sth.getPicpath();
		sth.setThumbPicpath(picpath);
		Integer addBaleGoods = bgd.addBaleGoods(sth);
		if(addBaleGoods>0) {
			return sth.getBaleGoodsId()+"";
		}else {
			return null;
		}
		
	}

	@Override
	public int modifyBaleGoods(BaleGoods bg) {
		int modifyBaleGoods = bgd.modifyBaleGoods(bg);
		return modifyBaleGoods;
	}

	@Override
	public int deleteBaleGoods(String baleGoodsId) {
		String[] id = baleGoodsId.split(",");
		int deleteBaleGoods = bgd.deleteBaleGoods(id);
		return deleteBaleGoods;
	}

	@Override
	public int deleteBaleGoodsOne(Integer baleGoodsId) {
		String[] id = {baleGoodsId.toString()};
		int deleteBaleGoods = bgd.deleteBaleGoods(id);
		return deleteBaleGoods;
	}
	/**
	 * 	查询可打包的商品名称id
	 */
	@Override
	public List<TansferReturn> selectCommonGoods() {
		List<TansferReturn> selectCommonGoodsList = bgd.selectCommonGoods();
		return selectCommonGoodsList;
	}

}
